/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.losalpes.data;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author FamiliaQA
 */
@Stateless
public class Persistence implements IPersistence{

    @PersistenceContext
    private EntityManager em;

    public Persistence() {
    }

    public void create(Object obj) {
        em.persist(obj);
    }

    public void update(Object obj) {
        em.merge(obj);
    }

    public void delete(Object obj) {
        em.remove(em.merge(obj));
    }

    public List findAll(Class c) {
        return em.createQuery("select O from " + c.getSimpleName() + " as O").getResultList();
    }

    public Object findById(Class c, Object id) {
        return em.find(c, id);
    }
 
}
